﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DesignMode.Cmd
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    double num1 = 0;
                    double num2 = 0;

                    Console.Write("请输入第1个数：");
                    try
                    {
                        num1 = double.Parse(Console.ReadLine());
                    }
                    catch
                    {
                        throw new Exception("第1个数必须为数字。");
                    }

                    Console.Write("请输入运算符号（+、-、*、/）：");
                    string numOperator = Console.ReadLine();
                    if (numOperator != "+" &&
                        numOperator != "-" &&
                        numOperator != "*" &&
                        numOperator != "/")
                    {
                        throw new Exception("运算符号输入错误。");
                    }

                    Console.Write("请输入第2个数：");
                    try
                    {
                        num2 = double.Parse(Console.ReadLine());
                    }
                    catch
                    {
                        throw new Exception("第2个数必须为数字。");
                    }

                    double num3 = 0;
                    switch (numOperator)
                    {
                        case "+":
                            {
                                num3 = num1 + num2;
                            }
                            break;
                        case "-":
                            {
                                num3 = num1 - num2;
                            }
                            break;
                        case "*":
                            {
                                num3 = num1 * num2;
                            }
                            break;
                        case "/":
                            {
                                if (num2 == 0)
                                {
                                    throw new Exception("除数不能为0。");
                                }
                                else
                                {
                                    num3 = num1 / num2;
                                }
                            }
                            break;
                    }

                    Console.WriteLine("结果为：" + num3);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                    Console.WriteLine("请继续输入。");
                }
                finally
                {
                    Console.WriteLine("---------------------------------");
                }
            }
        }
    }
}
